class PhoneNumber {

    private final String numberString;

    PhoneNumber(String inputString) {
//        remove ".", "-", BlankSpace, "()"
        String iString = inputString.replaceAll("\\.|-|\\(|\\)|\\s", "");

//        is all digit?
        if (!iString.matches("\\d+$")) {
            throw new IllegalArgumentException("Illegal character in phone number. Only digits, spaces, parentheses, hyphens or dots accepted.");
        }

        if (iString.length() != 10 && iString.length() != 11) {
            throw new IllegalArgumentException("Number must be 10 or 11 digits");
        }

        if (!iString.startsWith("1")) {
            throw new IllegalArgumentException("Can only have 11 digits if number starts with '1'");
        }

        this.numberString = iString;
    }


    String getNumber() {
        return this.numberString.substring(this.numberString.length() % 10);
    }
}